using FPLibrary;
using UnityEngine;

namespace PathX
{
    static class PhysicX
    {
        public static bool CheckCapsule(UnityEngine.Vector3 start, UnityEngine.Vector3 end, float radius, int layermask)
        {
            return UnityEngine.Physics.CheckCapsule(start, end, radius, layermask);
        }

        public static bool CheckCapsule(UnityEngine.Vector3 start, UnityEngine.Vector3 end, float radius)
        {
            return UnityEngine.Physics.CheckCapsule(start, end, radius);
        }
        
        public static bool IsBlocked(FPVector position, float blockThreshold)
        {
            var above = position.ToVector() + Vector3.up;
            var below = position.ToVector() + Vector3.down;
            if (PhysicX.CheckCapsule(above, below, blockThreshold, Layers.blocks))
            {
                return true;
            }

            //Doing a simple raycast does not cut it in scenarios where level geometry is made up from multiple pieces, as the ray can slip through the most minuscule of cracks
            //Luckily capsule check is just as fast
            above = position.ToVector() + Vector3.up;
            below = position.ToVector() + Vector3.down;

            return !PhysicX.CheckCapsule(above, below, 0.01f, Layers.terrain);
        }
    }
}